package com.ok.sb.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author ok
 * @date 2021/8/12 16:17
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "ResultVO对象", description = "封装接口返回给前端的数据。")
public class ResultVO {
    public static final int SUCCESS = 1000;
    public static final int FAIL = 1001;

    @ApiModelProperty(value = "响应状态码", dataType = "int")
    private int code;
    @ApiModelProperty(value = "响应信息", dataType = "String")
    private String msg;
    @ApiModelProperty(value = "响应数据")
    private Object data;

    /**
     * 只有消息
     *
     * @param msg
     * @return
     */
    public static ResultVO success(String msg) {
        return success(msg, null);
    }

    /**
     * 只有对象
     *
     * @param data
     * @return
     */
    public static ResultVO success(Object data) {
        return success(null, data);
    }

    /**
     * 有消息， 有对象
     *
     * @param msg
     * @return
     */
    public static ResultVO success(String msg, Object data) {
        return ResultVO.builder().code(SUCCESS).msg(msg).data(data).build();
    }

    /**
     * 只有消息
     *
     * @param msg
     * @return
     */
    public static ResultVO fail(String msg) {
        return fail(msg, null);
    }

    /**
     * 只有对象
     *
     * @param data
     * @return
     */
    public static ResultVO fail(Object data) {
        return fail(null, data);
    }

    /**
     * 有消息， 有对象
     *
     * @param msg
     * @return
     */
    public static ResultVO fail(String msg, Object data) {
        return ResultVO.builder().code(FAIL).msg(msg).data(data).build();
    }
}